package com.yxs.school.api.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yxs.school.api.entity.Collect;
import com.yxs.school.api.service.impl.CollectServiceImpl;
import com.yxs.school.result.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 收藏 前端控制器
 * </p>
 *
 * @author whp
 * @since 2019-11-15
 */
@RestController
@RequestMapping("/api/collect")
public class CollectController {
    @Resource
    private CollectServiceImpl collectService;
    @PostMapping("save")
    public R save(@RequestBody Collect collect){
        boolean flag=collectService.save(collect);
        if (flag){
            return R.data(200,null,"成功");
        }else {
            return R.data(400,null,"失败");
        }
    }
    @DeleteMapping("delete")
    public R delete(@RequestBody List<Integer> ids){
        boolean flag=
        collectService.removeByIds(ids);
        if (flag) {
            return R.data(200,null,"成功");
        }else {
            return R.data(400,null,"失败");
        }
    }
    @PutMapping("update")
    public R update(@RequestBody Collect collect){
        boolean flag=collectService.updateById(collect);
        if (flag){
            return R.data(200,null,"成功");
        }else {
            return R.data(400,null,"失败");
        }
    }
    public R list(Integer page,Integer size,String group){
//        PageHelper
        List<Collect> list=collectService.list(new QueryWrapper<Collect>()
                .groupBy(group)
                .orderByAsc("collect_time"));
        return R.data(200,list,"成功");
    }
}
